package pers.cz.config;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

/**
 * @program: JefConfig
 * @description: 自定义配置类
 * @author: Cheng Zhi
 * @create: 2022-07-14 11:07
 **/
public class JefConfiguration {

    private static String fileName = "jef.properties";
    //private static String fileName = "D:\\Java\\Project\\JefConfig\\src\\resource\\jef.properties";
    private static Map<String, String> cache = new HashMap<String, String>();
    private static File file;
    static Configuration configuration = null;

    static {
        if (configuration == null) {
            // JVM启动参数中添加-Djef.properties=xxx.properties 来指定自己的配置文件或者System.setProperty()来设置
            String property = System.getProperty("jef.properties");

            if (property == null) {
                property = fileName;
            }
            configuration = new Configuration(property);
        }
    }

    public static double getDouble(ConfigItem configItem, int defaultValue) {

        return configuration.getDouble(configItem, defaultValue);
    }

    public static long getLong(ConfigItem configItem, long defaultValue) {

        return configuration.getLong(configItem, defaultValue);
    }

    public static boolean getBoolean(ConfigItem configItem, boolean defaultValue) {

        return configuration.getBoolean(configItem, defaultValue);
    }

    public static int getInt(ConfigItem configItem, int defaultValue) {

        return configuration.getInt(configItem, defaultValue);
    }

    public static String get(ConfigItem configItem) {

        String key = configItem.toString().toLowerCase();
        return configuration.get(key, "");
    }

    public static String get(ConfigItem configItem, String defalutKeyValue) {
        String key = configItem.toString().toLowerCase();
        return configuration.get(key, defalutKeyValue);
    }
}
